<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
                <label class="el-form-item-label">电芯条码</label>
                <el-input v-model="query.productSn" clearable placeholder="电芯条码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">档位</label>
                <el-input v-model="query.gear" clearable placeholder="档位" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <el-button type="warning" @click="clearCellCapacity">清空档位数据</el-button>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="电芯条码">
            <el-input v-model="form.productSn" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="DC容量">
            <el-input v-model="form.capacity" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="productSn" label="电芯条码" />
        <el-table-column prop="capacity" label="DC容量" />
        <el-table-column prop="gear" label="档位" />
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','dataCellCapacity:edit','dataCellCapacity:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDataCellCapacity from '@/api/data/dataCellCapacity'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import dataCellCapcity from '../../../api/data/dataCellCapacity'

const defaultForm = { productSn: null, capacity: null, createBy: null, createTime: null, updateBy: null, updateTime: null, id: null }
export default {
  name: 'DataCellCapacity',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '电芯容量', url: 'api/dataCellCapacity', idField: 'id', sort: 'id,desc',
      crudMethod: { ...crudDataCellCapacity },
      optShow:{add: false,
        edit: false,
        del: true,
        download: false,
        reset: true,
        import: true
      },

      importConfig:{
        //模板地址
        templateUrl: '/template/电芯容量导入模板.xlsx',
        //解析Excel成功回调
        onSuccess: '',
        importUrl: '/api/dataCellCapacity/importCellCapacityBatch',
      },
    })},
  data() {
    return {
      permission: {
        add: ['admin', 'dataCellCapacity:add'],
        edit: ['admin', 'dataCellCapacity:edit'],
        del: ['admin', 'dataCellCapacity:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'productSn', display_name: '电芯条码' },
        { key: 'capacity', display_name: '电芯容量' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    clearCellCapacity(){
      this.$confirm('确定要清空电芯档位数据吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        //发送清空请求
          dataCellCapcity.clearCellCapacity().then(Response=>{
            console.log("删除成功");
            console.log(Response);
            this.$message({
            type: 'success',
            message: '删除成功!'
            });
            //刷新页面
            location.reload()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    }
  }
}
</script>

<style scoped>

</style>
